import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import Index from '../views/Index.vue'
import UserManager from '../views/user/UserManager';
import ExpManager from '../views/experiment/ExpManager'
import ExpComment from '../views/experiment/ExpComment'
import ProjectManage from '../views/project/ProjectManage'
import ProjectComment from '../views/project/ProjectComment'
import ExpView from '../views/ExpView.vue'
import ProjectView from '../views/ProjectView.vue'
import MainLoad from '../views/MainLoad.vue'
import PersonView from '../views/PersonView'
import register from '../views/register'

Vue.use(VueRouter)

//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject);
  return originalReplace.call(this, location).catch(err => err);
};


const routes = [
  {
    path: '/',
    name: '主页',
    component: Index,
    children: [
      { path: '/expview', name: '实验页', component: ExpView, },
      { path: '/projectview', name: '项目页', component: ProjectView, },
      { path: '/mainload', name: '项目页', component: MainLoad, },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    hidden: true
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: [
      { path: '/usermanager', name: '用户管理', component: UserManager, },
      { path: '/expmanager', name: '实验管理', component: ExpManager, },
      { path: '/expcomment', name: '实验管理', component: ExpComment, },
      { path: '/projectmanage', name: '项目管理', component: ProjectManage, },
      { path: '/projectcomment', name: '项目管理', component: ProjectComment, },

    ]
  },
  {
    path: '/personview',
    name: '个人信息',
    component: PersonView,
  },
  {
    path: '/register',
    name: '注册页面',
    component: register,
  },
]

const router = new VueRouter({
  routes
})

export default router
